package middle;

public class Solution_413 {

    public int numberOfArithmeticSlices(int[] nums) {
        int count = 0;
        int[] sub = new int[nums.length - 1];
        for (int i = 0; i < nums.length - 1; i++) {
            sub[i] = nums[i + 1] - nums[i];
        }
        // firstIndex 第一个不同差值的数字的下标
        for (int i = 1, firstIndex = 0; i < sub.length; i++) {
            if (sub[i] == sub[i - 1]) {
                count += (i - firstIndex);
                System.out.println(i - firstIndex);
            } else {
                firstIndex = i;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_413 model = new Solution_413();
//        System.out.println(model.numberOfArithmeticSlices(new int[]{1, 2, 3, 4}));
//        System.out.println(model.numberOfArithmeticSlices(new int[]{1, 2, 3, 4, 5, 6, 7}));
        System.out.println(model.numberOfArithmeticSlices(new int[]{-1, -9, 3, 4, 5, 6, 7, 9, 12, 13, 14, 15, 16, 8}));
//        System.out.println(model.numberOfArithmeticSlices(new int[]{1}));
    }
}
